﻿using Medicine.Entity;
using Medicine.Service;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Medicine.View
{
    public partial class UpdateMedicine : Form
    {
        private Medicin m;
        private MedicineServie ms = new MedicineServie();
        public UpdateMedicine(Medicin m)
        {
            InitializeComponent();
            this.m = m;
            this.textBox1.Text =m.Name;
            this.textBox2.Text =m.Price.ToString();
            this.richTextBox1.Text =m.Information;
            if (m.Ison == 0)
                this.checkBox1.Checked = false;
            else
                this.checkBox1.Checked = true;
        }

        private void UpdateMedicine_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            m.Name = this.textBox1.Text.Trim();
            try
            {
                m.Price = float.Parse(this.textBox2.Text.Trim());
            }
            catch (Exception c)
            {
                m.Price = 0;
            }
            m.Information = this.richTextBox1.Text.Trim();
            if (this.checkBox1.Checked == false)
                m.Ison = 0;
            else
                m.Ison = 1;
            ms.update(m);
            this.Close();
        }
    }
}
